<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Advertise_Model extends CI_Model{
	protected $_name = "advertise";
	protected $_primary = "AdsId";
	var $Name = "Name", $Link = "Link", $Image = "Image", $Target = "Target", $Position = "Position", $Order = "`Order`", $Status = "Status";
	
	function countAds(){
		$this->db->where($this->Status, 1);
		$this->db->or_where($this->Status, 2);
		$query = $this->db->get($this->_name);
		return $query->num_rows();
	}
	
	function getAdsLimit($currentPage, $number){
		$where = "(".$this->Status."=1 OR ".$this->Status."=2)";
		$this->db->where($where);
		$this->db->limit($number, $currentPage);
		$query = $this->db->get($this->_name);
		if($query->num_rows() > 0){
			$i = $currentPage;
			$j = 0;
			foreach($query->result() as $row){
				$data[$j] = $row;
				$i++;
				$data[$j]->stt = $i;
				$j++;
			}
			return $data;
		}
		return false;
	}
	
	function searchAds($keysearch){
		$this->db->like($this->Name, $keysearch);
		$where = "(".$this->Status."=1 OR ".$this->Status."=2)";
		$this->db->where($where);
		$query = $this->db->get($this->_name);
		if($query->num_rows() > 0){
			$i = 0;
			$j = 0;
			foreach($query->result() as $row){
				$data[$j] = $row;
				$i++;
				$data[$j]->stt = $i;
				$j++;
			}
			return $data;
		}
		return false;
	}
	
}